package oocl.eshop.ui.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import oocl.eshop.po.Merchant;
import oocl.eshop.service.MerchantManager;
import oocl.eshop.service.impl.MerchantManagerImpl;

/**
 * Servlet implementation class LoginServlet
 */
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private MerchantManager merchantManager=new MerchantManagerImpl();
       
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }   

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		System.out.println("Login....");
//		System.out.println(request.getParameter("mPassword"));
		String mTel=request.getParameter("mTel");
		String mPassword=request.getParameter("mPassword");
//		System.out.println(mTel);
//		System.out.println(mPassword);
		//方法一：调用service，取得一个实体的信息，
		Merchant merchant=merchantManager.loginSystem(mTel, mPassword);
//		Merchant merchant=new Merchant("kinva", "13123456789", "kinva", "123456789012345678", "http://www.005.tv/uploads/allimg/160617/1P3391451-3.jpg", "东岸村村口", "mdzz", "http://img3.duitang.com/uploads/item/201606/18/20160618112434_4eQMV.thumb.224_0.jpeg");
//		merchant.setmStatus(1);
		if (merchant==null) {
			request.setAttribute("warningMsg3", "用户名或密码错误!!");
			request.getRequestDispatcher("login.jsp").forward(request, response);
		} else {
			HttpSession session=request.getSession();
			session.setAttribute("mTel", mTel);
			session.setAttribute("merchant", merchant);
			System.out.println(merchant.getmId());
			request.getRequestDispatcher("showHomePage").forward(request, response);
//			response.sendRedirect("showHomePage");
		}
		
	   
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}

}
